<template>
    <button class="base-button" :class="[
        `type-${type}`,
        { 'is-loading': loading }
    ]" :disabled="disabled || loading" @click="$emit('click', $event)">
        <span v-if="loading" class="loading-spinner"></span>
        <slot></slot>
    </button>
</template>

<script setup>
defineProps({
    type: {
        type: String,
        default: 'default'
    },
    loading: {
        type: Boolean,
        default: false
    },
    disabled: {
        type: Boolean,
        default: false
    }
})

defineEmits(['click'])
</script>

<style scoped>
.base-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 var(--space-3);
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast) var(--ease-out);
    gap: var(--space-2);
}

.type-default {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.type-primary {
    background-color: var(--primary-color);
    color: white;
}

.type-default:hover {
    background-color: var(--border-color);
}

.type-primary:hover {
    background-color: var(--primary-hover);
}

.base-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
</style>